library(lme4)
library(MuMIn)
library(multcomp)
data<-read.table(file="S2 Data.txt", header=TRUE, sep="\t")
data_c <- transform(data,cAge=Age-mean(Age),cWords=Words-mean(Words),cPropositions=Propositions-mean(Propositions),cGood=Good-mean(Good),cBad=Bad-mean(Bad),cSurvival=Survival-mean(Survival),cSocial=Social-mean(Social),cMale_Stereo=Male_Stereo-mean(Male_Stereo),cFemale_Stereo=Female_Stereo-mean(Female_Stereo),cEDA_Score=EDA_Score-mean(EDA_Score),cEmotional=Emotional-mean(Emotional))
#fitting models for testing H4 and H5
null<-glmer(Recall ~ (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa",calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
gen_only<-glmer(Recall ~ Generation+ (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa",calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m01<-glmer(Recall ~ cAge + Gender + cWords + cPropositions + cGood + cBad + cSurvival + cSocial + cMale_Stereo + cFemale_Stereo + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa",calc.derivs = FALSE, optCtrl = list(maxfun = 100000)))
m02<-glmer(Recall ~ Gender + cWords + cPropositions + cGood + cBad + cSurvival + cSocial + cMale_Stereo + cFemale_Stereo + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m03<-glmer(Recall ~ Gender + cWords + cPropositions + cGood + cBad + cSocial + cMale_Stereo + cFemale_Stereo + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m04<-glmer(Recall ~ Gender + cWords + cPropositions + cGood + cSocial + cMale_Stereo + cFemale_Stereo + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m05<-glmer(Recall ~ Gender + cWords + cPropositions + cGood + cMale_Stereo + cFemale_Stereo + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa",calc.derivs = FALSE, optCtrl = list(maxfun = 100000)))
m06<-glmer(Recall ~ Gender + cWords + cGood + cMale_Stereo + cFemale_Stereo + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m07<-glmer(Recall ~ Gender + cWords + cGood + cFemale_Stereo + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m08<-glmer(Recall ~ Gender + cWords + cGood + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m09<-glmer(Recall ~ Gender + cGood + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m10<-glmer(Recall ~ cWords + cGood + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m11<-glmer(Recall ~ Gender + cWords + Emotion + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa",calc.derivs = FALSE, optCtrl = list(maxfun = 100000)))
m12<-glmer(Recall ~ Gender + cWords + cGood + Generation + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m13<-glmer(Recall ~ Gender + cWords + cGood + Emotion + cEDA_Score + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
m14<-glmer(Recall ~ Gender + cWords + cGood + Emotion + Generation + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa", calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
#model selection table
model.sel(m01,m02,m03,m04,m05,m06,m07,m08,m09,m10,m11,m12,m13,m14)
#model averaging
average_model<-model.avg(m06,m07,m08,m09,m14)
#emotion comparison using best model (m08)
m08_mcp<-glht(m08,linfct=mcp(Emotion="Tukey"))
#testing H6
H6test<-glmer(Recall ~ Moral.Category + Generation + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa",calc.derivs = FALSE,optCtrl = list(maxfun = 100000)))
anova(gen_only,H6test)
H6_mcp<-glht(H6test,linfct=mcp(Moral.Category="Tukey"))
#testing H7
H7test<-glmer(Recall ~ Gender + cWords + cGood + Emotion + Generation + cEmotional + (1|Set/Generation/Participant/Vignette), data = data_c, family = binomial, nAGQ = 1,control=glmerControl(optimizer="bobyqa",calc.derivs = FALSE, optCtrl = list(maxfun = 100000)))
anova(m08,H7test)
#testing for recall of moral propositions
goodMP<-glmer(Moral_Prop~ cGood + Generation + (1|Set/Generation/Participant/Vignette),family = binomial, nAGQ = 1, data = data_c, control=glmerControl(optimizer="Nelder_Mead",calc.derivs = FALSE, optCtrl = list(maxfun = 100000)))
anova(goodMP,gen_onlyMP)
badMP<-glmer(Moral_Prop~ cBad + Generation + (1|Set/Generation/Participant/Vignette),family = binomial, nAGQ = 1, data = data_c, control=glmerControl(optimizer="Nelder_Mead",calc.derivs = FALSE, optCtrl = list(maxfun = 100000)))
anova(badMP,gen_onlyMP)
anova(badMP,goodMP)